public class ArrBinaryTreeDemo {
    public static void main(String[] args) {
        int[] array = {1,2,3,4,5,6,7};
        ArrBinaryTree arrBinaryTree = new ArrBinaryTree(array);
        System.out.println("前序遍历");
        arrBinaryTree.preOrder();
        System.out.println("中序遍历");
        arrBinaryTree.infixOrder();
        System.out.println("后序遍历");
        arrBinaryTree.postOrder();
    }
}

class ArrBinaryTree{
    private int[] array;

    public ArrBinaryTree(int[] array) {
        this.array = array;
    }

    //重载preOrder
    public void preOrder(){
        this.preOrder(0);
    }

    //重载infixOrder
    public void infixOrder(){
        this.infixOrder(0);
    }

    //重载postOrder
    public void postOrder(){
        this.postOrder(0);
    }

    /**
     * 前序遍历
     * @param index:数组下标
     */
    public void preOrder(int index){
        if(array == null || array.length == 0){
            System.out.println("数组为空");
        }

        System.out.println(array[index]);

        if((index * 2 + 1) < array.length){
            preOrder(index * 2 + 1);
        }

        if((index * 2 + 2) < array.length){
            preOrder(index * 2 + 2);
        }
    }

    /**
     * 中序遍历
     * @param index:数组下标
     */
    public void infixOrder(int index){
        if(array == null || array.length == 0){
            System.out.println("数组为空");
        }

        if((2 * index + 1) < array.length){
            infixOrder(2 * index + 1);
        }

        System.out.println(array[index]);

        if((2 * index + 2) < array.length){
            infixOrder(2 * index + 2);
        }
    }

    /**
     * 后序遍历
     * @param index:数组下标
     */
    public void postOrder(int index){
        if(array == null || array.length == 0){
            System.out.println("数组为空");
        }

        if((2 * index + 1) < array.length){
            postOrder(2 * index + 1);
        }

        if((2 * index + 2) < array.length){
            postOrder(2 * index + 2);
        }

        System.out.println(array[index]);
    }
}